home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / BTREE.ZIP / BTREEHLP.TXT < prev    next >
Encoding:
Text File  |  1994-11-15  |  14.9 KB  |  571 lines

  1. Balanced Binary Tree Templates
  2.  
  3.  
  4. TBPlusTree template
  5.  
  6. Syntax
  7. template <class T> class TBPlusTree;
  8.  
  9. Header File
  10. btreeimp.h
  11.  
  12. Description
  13. Implements a balanced tree of objects of type T.
  14. TStandardAllocator is used to manage memory.
  15.  
  16. Type Definitions
  17. typedef int (*CompFunc) (const T&, void*)
  18. typedef int (*CondFunc) (const T&, void*)
  19. typedef void (*IterFunc) (T&, void*)
  20.  
  21. Public Constructor
  22. TBPlusTree (void)
  23.  
  24. Public Member Functions
  25. int Add (const T& t)
  26. int Destroy (const T& t)
  27. int DestroyFirst (void)
  28. int DestroyLast (void)
  29. int Detach (const T& t)
  30. int DetachFirst (void)
  31. int DetachLast (void)
  32. T* Find (const T& t) const
  33. T* First (void) const
  34. T* FirstThat (CondFunc cond, void* args) const
  35. void Flush (void)
  36. void ForEach (IterFunc iter, void* args)
  37. unsigned GetItemsInContainer (void) const
  38. int HasMember (const T& t) const
  39. int IsEmpty (void) const
  40. T* Last (void) const
  41. T* LastThat (CondFunc, void* t) const
  42. T* Search (CompFunc, void* t) const
  43.  
  44. Syntax
  45. TBPlusTree (void)
  46.  
  47. Description
  48. Creates a tree which is initially empty.
  49.  
  50. Syntax
  51. int Add (const T& t)
  52.  
  53. Description
  54. Adds a T object to the balanced tree. If the object already exists in the tree, 
  55. Add fails. Add returns 0 if it couldnÆt add the object.
  56.  
  57. Syntax
  58. int Destroy (const T& t)
  59.  
  60. Description
  61. Removes the object from the tree.
  62.  
  63. Syntax
  64. int DestroyFirst (void)
  65.  
  66. Description
  67. Removes the first (lowest valued) object from the tree.
  68.  
  69. Syntax
  70. int DestroyLast (void)
  71.  
  72. Description
  73. Removes the last (highest valued) object from the tree.
  74.  
  75. Syntax
  76. int Detach (const T& t)
  77.  
  78. Description
  79. Removes the object from the tree.
  80.  
  81. Syntax
  82. int DetachFirst (void)
  83.  
  84. Description
  85. Removes the first (lowest valued) object from the tree.
  86.  
  87. Syntax
  88. int DetachLast (void)
  89.  
  90. Description
  91. Removes the last (highest valued) object from the tree.
  92.  
  93. Syntax
  94. T* Find (const T& t) const
  95.  
  96. Description
  97. Finds the specified object and returns a pointer to it. Returns 0 is the object 
  98. is not found in the tree.
  99.  
  100. Syntax
  101. T* First (void) const
  102.  
  103. Description
  104. Returns a pointer to the first (lowest valued) object in the tree. Returns 0 is 
  105. the tree is empty.
  106.  
  107. Syntax
  108. T* FirstThat (CondFunc cond, void* args) const
  109.  
  110. Description
  111. Returns a pointer to the first object in the tree that satisfies a given 
  112. condition. You supply a test function pointer cond that returns true for a 
  113. certain condition. You can pass arbitrary arguments via args. Returns 0 if no 
  114. object in the tree meets the condition.
  115.  
  116. Syntax
  117. void Flush (void)
  118.  
  119. Description
  120. Removes all the elements in the tree without destroying the tree.
  121.  
  122. Syntax
  123. void ForEach (IterFunc iter, void* args)
  124.  
  125. Description
  126. ForEach creates an internal iterator to execute the given function for each 
  127. element in the array. The args argument lets you pass arbitrary data to this 
  128. function.
  129.  
  130. Syntax
  131. unsigned GetItemsInContainer (void) const
  132.  
  133. Description
  134. Returns the number of items in the tree.
  135.  
  136. Syntax
  137. int HasMember (const T& t) const
  138.  
  139. Description
  140. Returns 1 is the given object is found in the tree, otherwise returns 0.
  141.  
  142. Syntax
  143. int IsEmpty (void) const
  144.  
  145. Description
  146. Returns 1 is the tree contains no elements, otherwise returns 0.
  147.  
  148. Syntax
  149. T* Last (void) const
  150.  
  151. Description
  152. Returns a pointer to the last (highest valued) object in the tree. Returns 0 if 
  153. the tree is empty.
  154.  
  155. Syntax
  156. T* LastThat (CondFunc cond, void* args) const
  157.  
  158. Description
  159. Returns a pointer to the last object in the array that satisfies a given 
  160. condition. You supply a test function pointer, cond, that returns true for a 
  161. certain condition. You can pass arbitrary arguments via args. Returns 0 if no 
  162. object in the tree meets the condition.
  163.  
  164. Syntax
  165. T* Search (CompFunc comp, void* args) const
  166.  
  167. Description
  168. Returns a pointer an object in the tree that satisfies a given condition. You 
  169. supply a compare function pointer, comp, whoÆs return value directs the search. 
  170. You can pass arbitrary arguments via args. Returns 0 if no object in the tree 
  171. satisfies the search.
  172.  
  173. If comp returns 0, the search ends, and a pointer to the current object is 
  174. returned.
  175. If comp returns < 0, the search continues with lower valued objects.
  176. If comp returns >0, the search continues with greater valued object.
  177.  
  178.  
  179. TBPlusTreeIterator template
  180.  
  181. Syntax
  182. template <class T> class TBPlusTreeIterator;
  183.  
  184. Header File
  185. btreeimp.h
  186.  
  187. Description
  188. Implements an iterator object to traverse TBPlusTree objects.
  189.  
  190. Public Constructors
  191. TBPlusTreeIterator (const TBPlusTree<T> &t)
  192. TBPlusTreeIterator (const TBPlusTree<T> &t, const T& start, const T& end)
  193.  
  194. Public Member Functions
  195. const T& Current (void) const
  196. void Restart (void)
  197. void Restart (const T& start, const T& end)
  198.  
  199. Operators
  200. const T& operator ++ (int)
  201. const T& operator ++ (void)
  202. const T& operator -- (int)
  203. const T& operator -- (void)
  204. operator int (void) const
  205.  
  206. Syntax
  207. TBPlusTreeIterator (const TBPlusTree<T> &t)
  208.  
  209. Description
  210. Creates an iterator to traverse the object t.
  211.  
  212. Syntax
  213. TBPlusTreeIterator (const TBPlusTree<T> &t, const T& start, const T& end)
  214.  
  215. Description
  216. Creates an iterator to traverse the object t. Limits the range of the iterator 
  217. to all elements whoÆs values lie between start and end inclusive. If start is 
  218. greater than end, the decrement operators should be used.
  219.  
  220. Note. The tree does not need to contain elements equal to start and end.
  221.  
  222. Syntax
  223. const T& Current (void) const
  224.  
  225. Description
  226. Returns the current object.
  227.  
  228. Syntax
  229. void Restart (void)
  230.  
  231. Description
  232. Restarts the iteration over the previous range.
  233.  
  234. Syntax
  235. void Restart (const T& start, const T& end)
  236.  
  237. Description
  238. Restarts the iteration over the given range. The range is inclusive of start and 
  239. end if values equal to start or end are found in the tree. If start is greater 
  240. than end, the decrement operators should be used.
  241.  
  242. Syntax
  243. const T& operator ++ (int)
  244.  
  245. Description
  246. Move to the next object, and return the object that was current before the move 
  247. (post-increment).
  248.  
  249. Syntax
  250. const T& operator ++ (void)
  251.  
  252. Description
  253. Move to the next object, and return the object that was current before the move 
  254. (pre-increment).
  255.  
  256. Syntax
  257. const T& operator -- (int)
  258.  
  259. Description
  260. Move to the previous object, and return the object that was current before the 
  261. move (post-decrement).
  262.  
  263. Syntax
  264. const T& operator -- (void)
  265.  
  266. Description
  267. Move to the previous object, and return the object that was current before the 
  268. move (pre-decrement).
  269.  
  270. Syntax
  271. operator int (void) const
  272.  
  273. Description
  274. Converts the iterator to an integer value for testing if objects remain in the 
  275. iterator. The iterator converts to 0 if nothing remains in the iterator.
  276.  
  277.  
  278. TIBPlusTree template
  279.  
  280. Syntax
  281. template <class T> class TIBPlusTree;
  282.  
  283. Header File
  284. btreeimp.h
  285.  
  286. Description
  287. Implements a indirect balanced tree of objects of type T.
  288. TStandardAllocator is used to manage memory.
  289.  
  290. Type Definitions
  291. typedef int (*CompFunc) (const T&, void*)
  292. typedef int (*CondFunc) (const T&, void*)
  293. typedef void (*IterFunc) (T&, void*)
  294.  
  295. Public Constructor
  296. TIBPlusTree (void)
  297.  
  298. Public Member Functions
  299. int Add (const T* t)
  300. int Destroy (const T* t)
  301. int DestroyFirst (void)
  302. int DestroyLast (void)
  303. int Detach (const T* t, DeleteType dt = NoDelete)
  304. int DetachFirst (DeleteType dt = NoDelete)
  305. int DetachLast (DeleteType dt = NoDelete)
  306. T* Find (const T* t) const
  307. T* First (void) const
  308. T* FirstThat (CondFunc cond, void* args) const
  309. void Flush (DeleteType dt = DefDelete)
  310. void ForEach (IterFunc iter, void* args)
  311. unsigned GetItemsInContainer (void) const
  312. int HasMember (const T* t) const
  313. int IsEmpty (void) const
  314. T* Last (void) const
  315. T* LastThat (CondFunc, void* t) const
  316. T* Search (CompFunc, void* t) const
  317.  
  318. Syntax
  319. TIBPlusTree (void)
  320.  
  321. Description
  322. Creates a tree which is initially empty.
  323.  
  324. Syntax
  325. int Add (const T* t)
  326.  
  327. Description
  328. Adds a pointer to the object T to the balanced tree. If the object already 
  329. exists in the tree, Add fails. Add returns 0 if it couldnÆt add the object.
  330.  
  331. Syntax
  332. int Destroy (const T* t)
  333.  
  334. Description
  335. Removes the object from the tree and deletes it.
  336.  
  337. Syntax
  338. int DestroyFirst (void)
  339.  
  340. Description
  341. Removes the first (lowest valued) object from the tree and deletes it.
  342.  
  343. Syntax
  344. int DestroyLast (void)
  345.  
  346. Description
  347. Removes the last (highest valued) object from the tree and deletes it.
  348.  
  349. Syntax
  350. int Detach (const T& t, DeleteType dt = NoDelete)
  351.  
  352. Description
  353. Removes the object from the tree. The value of dt and the current ownership 
  354. setting determine whether the object itself will be deleted. DeleteType is 
  355. defined in the base class TShouldDelete as enum { NoDelete, DefDelete, Delete }. 
  356. The default value of dt, NoDelete, means that the object will not be deleted 
  357. regardless of ownership. With dt set to Delete, the object will be deleted 
  358. regardless of ownership. If dt is set to DefDelete, the object will be deleted 
  359. only if the tree owns its elements.
  360.  
  361. Syntax
  362. int DetachFirst (DeleteType dt = NoDelete)
  363.  
  364. Description
  365. Removes the first (lowest valued) object from the tree. The value of dt and the 
  366. current ownership setting determine whether the object itself will be deleted. 
  367. DeleteType is defined in the base class TShouldDelete as enum { NoDelete, 
  368. DefDelete, Delete }. The default value of dt, NoDelete, means that the object 
  369. will not be deleted regardless of ownership. With dt set to Delete, the object 
  370. will be deleted regardless of ownership. If dt is set to DefDelete, the object 
  371. will be deleted only if the tree owns its elements.
  372.  
  373. Syntax
  374. int DetachLast (DeleteType dt = NoDelete)
  375.  
  376. Description
  377. Removes the last (highest valued) object from the tree. The value of dt and the 
  378. current ownership setting determine whether the object itself will be deleted. 
  379. DeleteType is defined in the base class TShouldDelete as enum { NoDelete, 
  380. DefDelete, Delete }. The default value of dt, NoDelete, means that the object 
  381. will not be deleted regardless of ownership. With dt set to Delete, the object 
  382. will be deleted regardless of ownership. If dt is set to DefDelete, the object 
  383. will be deleted only if the tree owns its elements.
  384.  
  385. Syntax
  386. T* Find (const T* t) const
  387.  
  388. Description
  389. Finds the specified object and returns a pointer to it. Returns 0 is the object 
  390. is not found in the tree.
  391.  
  392. Syntax
  393. T* First (void) const
  394.  
  395. Description
  396. Returns a pointer to the first (lowest valued) object in the tree. Returns 0 is 
  397. the tree is empty.
  398.  
  399. Syntax
  400. T* FirstThat (CondFunc cond, void* args) const
  401.  
  402. Description
  403. Returns a pointer to the first object in the tree that satisfies a given 
  404. condition. You supply a test function pointer cond that returns true for a 
  405. certain condition. You can pass arbitrary arguments via args. Returns 0 if no 
  406. object in the tree meets the condition.
  407.  
  408. Syntax
  409. void Flush (DeleteType dt = DefDelete)
  410.  
  411. Description
  412. Removes all the elements in the tree without destroying the tree. The value of 
  413. dt determines whether the elements themselves are destroyed. By default, the 
  414. ownership status of the array determines their fate, as explained in the Detach 
  415. member function. You can also set dt to Delete and NoDelete.
  416.  
  417. Syntax
  418. void ForEach (IterFunc iter, void* args)
  419.  
  420. Description
  421. ForEach creates an internal iterator to execute the given function for each 
  422. element in the array. The args argument lets you pass arbitrary data to this 
  423. function.
  424.  
  425. Syntax
  426. unsigned GetItemsInContainer (void) const
  427.  
  428. Description
  429. Returns the number of items in the tree.
  430.  
  431. Syntax
  432. int HasMember (const T* t) const
  433.  
  434. Description
  435. Returns 1 is the given object is found in the tree, otherwise returns 0.
  436.  
  437. Syntax
  438. int IsEmpty (void) const
  439.  
  440. Description
  441. Returns 1 is the tree contains no elements, otherwise returns 0.
  442.  
  443. Syntax
  444. T* Last (void) const
  445.  
  446. Description
  447. Returns a pointer to the last (highest valued) object in the tree. Returns 0 if 
  448. the tree is empty.
  449.  
  450. Syntax
  451. T* LastThat (CondFunc cond, void* args) const
  452.  
  453. Description
  454. Returns a pointer to the last object in the array that satisfies a given 
  455. condition. You supply a test function pointer, cond, that returns true for a 
  456. certain condition. You can pass arbitrary arguments via args. Returns 0 if no 
  457. object in the tree meets the condition.
  458.  
  459. Syntax
  460. T* Search (CompFunc comp, void* args) const
  461.  
  462. Description
  463. Returns a pointer an object in the tree that satisfies a given condition. You 
  464. supply a compare function pointer, comp, whoÆs return value directs the search. 
  465. You can pass arbitrary arguments via args. Returns 0 if no object in the tree 
  466. satisfies the search.
  467.  
  468. If comp returns 0, the search ends, and a pointer to the current object is 
  469. returned.
  470. If comp returns < 0, the search continues with lower valued objects.
  471. If comp returns >0, the search continues with greater valued object.
  472.  
  473.  
  474. TIBPlusTreeIterator template
  475.  
  476. Syntax
  477. template <class T> class TIBPlusTreeIterator;
  478.  
  479. Header File
  480. btreeimp.h
  481.  
  482. Description
  483. Implements an iterator object to traverse TIBPlusTree objects.
  484.  
  485. Public Constructors
  486. TIBPlusTreeIterator (const TIBPlusTree<T> &t)
  487. TIBPlusTreeIterator (const TIBPlusTree<T> &t, const T* start, const T* end)
  488.  
  489. Public Member Functions
  490. const T* Current (void) const
  491. void Restart (void)
  492. void Restart (const T* start, const T* end)
  493.  
  494. Operators
  495. const T* operator ++ (int)
  496. const T* operator ++ (void)
  497. const T* operator -- (int)
  498. const T* operator -- (void)
  499. operator int (void) const
  500.  
  501. Syntax
  502. TIBPlusTreeIterator (const TIBPlusTree<T> &t)
  503.  
  504. Description
  505. Creates an iterator to traverse the object t.
  506.  
  507. Syntax
  508. TIBPlusTreeIterator (const TIBPlusTree<T> &t, const T* start, const T* end)
  509.  
  510. Description
  511. Creates an iterator to traverse the object t. Limits the range of the iterator 
  512. to all elements whoÆs values lie between start and end inclusive. If start is 
  513. greater than end, the decrement operators should be used.
  514.  
  515. Note. The tree does not need to contain elements equal to start and end.
  516.  
  517. Syntax
  518. const T* Current (void) const
  519.  
  520. Description
  521. Returns the current object.
  522.  
  523. Syntax
  524. void Restart (void)
  525.  
  526. Description
  527. Restarts the iteration over the previous range.
  528.  
  529. Syntax
  530. void Restart (const T* start, const T* end)
  531.  
  532. Description
  533. Restarts the iteration over the given range. The range is inclusive of start and 
  534. end if values equal to start or end are found in the tree. If start is greater 
  535. than end, the decrement operators should be used.
  536.  
  537. Syntax
  538. const T* operator ++ (int)
  539.  
  540. Description
  541. Move to the next object, and return the object that was current before the move 
  542. (post-increment).
  543.  
  544. Syntax
  545. const T* operator ++ (void)
  546.  
  547. Description
  548. Move to the next object, and return the object that was current before the move 
  549. (pre-increment).
  550.  
  551. Syntax
  552. const T* operator -- (int)
  553.  
  554. Description
  555. Move to the previous object, and return the object that was current before the 
  556. move (post-decrement).
  557.  
  558. Syntax
  559. const T* operator -- (void)
  560.  
  561. Description
  562. Move to the previous object, and return the object that was current before the 
  563. move (pre-decrement).
  564.  
  565. Syntax
  566. operator int (void) const
  567.  
  568. Description
  569. Converts the iterator to an integer value for testing if objects remain in the 
  570. iterator. The iterator converts to 0 if nothing remains in the iterator.
  571.